package com.tangl.demo.controller.elasticsearch;

import com.tangl.demo.Document.elasticsearch.DocBean;
import com.tangl.demo.repository.elasticsearch.ElasticRepository;
import com.tangl.demo.service.IElasticService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @author: TangLiang
 * @date: 2020/8/11 14:08
 * @since: 1.0
 */
@RestController
@Slf4j
@RequestMapping("/elastic")
@Api(tags = "搜索")
public class ElasticController {

//    @Autowired
//    private IElasticService elasticService;
//    @Autowired
//    private ElasticRepository elasticRepository;
//
//    @GetMapping("/init")
//    @ApiOperation("创建数据")
//    public void init() {
//        //elasticService.createIndex();
//        //DocBean docBean = new DocBean(100L, "XX0193", "XX8064", "xxxxxx", 1);
//        List<DocBean> list = new ArrayList<>();
//        list.add(new DocBean(1L, "XX0193", "XX8064", "xxxxxx", 1));
//        list.add(new DocBean(2L, "XX0210", "XX7475", "xxxxxxxxxx", 1));
//        list.add(new DocBean(3L, "XX0257", "XX8097", "xxxxxxxxxxxxxxxxxx", 1));
//        elasticService.saveAll(list);
//        //elasticService.save(docBean);
//    }
//
//    @GetMapping("/all")
//    @ApiOperation("查询所有")
//    public Iterator<DocBean> all() {
//        return elasticService.findAll();
//    }
//
//    @GetMapping("/findBy")
//    @ApiOperation("条件查询")
//    public Map findBy() {
//        Map result = new HashMap();
//        Page<DocBean> pageList = elasticService.findByContentLike("XX02");
//        result.put("success", true);
//        result.put("pageList", pageList);
//        return result;
//    }
//
//    @GetMapping("/delete")
//    @ApiOperation("删除所有")
//    public Map delete() {
//        Map result = new HashMap();
//        elasticService.deleteAll();
//        result.put("success", true);
//        return result;
//    }

}
